import os

from django.core.files.uploadedfile import InMemoryUploadedFile
from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
def uploadfile(request):
    if request.method=='GET':
        return render(request,'upload.html')

    post_datas = request.POST
    files_datas = request.FILES
    print('post_datas=',post_datas,'files_datas=',files_datas)

    print(request.path)

    meta = request.META
    print(type(meta),meta)

    qs = meta.get('QUERY_STRING')
    remote_addr = meta.get('REMOTE_ADDR')
    remote_host = meta.get('REMOTE_HOST')
    request_method=meta.get('REQUEST_METHOD')
    request_method=meta['REQUEST_METHOD']
    print('query_string=',qs)
    print('remote_addr=',remote_addr)
    print('remote_host=',remote_host)
    print('request_method=',request_method)


    # myfile:InMemoryUploadedFile = files_datas.get('myfile')
    # print('size=',myfile.size)
    # print('name=',myfile.name)
    # print('file=',myfile.file)
    # print('content_type=',myfile.content_type)
    #
    # upload_dir= 'uploaddir'
    # if not os.path.exists(upload_dir):
    #     os.mkdir(upload_dir)
    # with open(os.path.join(upload_dir,myfile.name),mode='wb') as fp:
    #     fp.write(myfile.read())
    # myfile.close()
    return HttpResponse('响应')